function AccountView() {
	
	var av = this;
        this.table = document.createElement('table');
        this.roles_table = document.createElement('table');

	
	this.addRow = function(row) {
		
		var tr = document.createElement('tr');
		$(tr).attr("id", "tr_"+row["id"]);

                var ftd = document.createElement('td');
		$(ftd).attr("id", "td_fname_"+row["id"]);
		$(ftd).html(row["fname"]);
		tr.appendChild(ftd);
                
                var ltd = document.createElement('td');
		$(ltd).attr("id", "td_lname_"+row["id"]);
		$(ltd).html(row["lname"]);
		tr.appendChild(ltd);
                
                var etd = document.createElement('td');
		$(etd).attr("id", "td_email_"+row["id"]);
		$(etd).html(row["email"]);
		tr.appendChild(etd);

                var ztd = document.createElement('td');
		$(ztd).attr("id", "td_zip_"+row["id"]);
		$(ztd).html(row["zip"]);
		tr.appendChild(ztd);
                
                var gtd = document.createElement('td');
		$(gtd).attr("id", "td_gender_"+row["id"]);
		$(gtd).html(row["gender"]);
		tr.appendChild(gtd);
                
                
		var action = '<div>\n\
			<span class="account_edit_action" id="edit_'+row["id"]+'">edit</span> | \n\
			<span class="account_delete_action" id="delete_'+row["id"]+'">delete</span>\n\
		</div>';

		var atd = document.createElement('td');
		$(atd).html(action);
		tr.appendChild(atd);
		
		av.table.appendChild(tr);
	},
	
	this.loadGreed = function(list) {
		
		for (var key in list) {
			
			var item = new Object();
			item["id"] = list[key].id;
			item["email"] = list[key].email;
			item["fname"] = list[key].fname;
                        item["lname"] = list[key].lname;
                        item["zip"] = list[key].zip;
                        item["gender"] = list[key].gender;
			
			av.addRow(item);
		}
		$("#account_list").append(av.table);
	},
        
        this.showRow = function(item, roles) {
            
            $("#account_form_fname").val(item.fname);
                $("#account_form_lname").val(item.lname);
		$("#account_form_email").val(item.email);
                $("#account_form_zip").val(item.zip);
                $("#account_form_gender").val(item.gender);
                
                
                
		$("#account_form_action").val("edit");
		$("#account_form_id").val(item.id);
                
                this.loadRoles(item.roles, roles);
        },
        
        this.addRole = function(row, action) {
		
		var tr = document.createElement('tr');
		$(tr).attr("id", "tr_"+row["id"]);

                var rvtd = document.createElement('td');
		$(rvtd).attr("id", "td_roleValue_"+row["id"]);
		$(rvtd).html(row["roleValue"]);
		tr.appendChild(rvtd);
                
                
                var action_html = '<div>\n';
                if (action == "add") {
                    action_html = action_html +
                        '<span class="role_add_action" id="add_'+row["id"]+'">add</span> | \n';
                }
                if (action == "delete") {
                    action_html = action_html +
                        '<span class="role_delete_action" id="delete_'+row["id"]+'">delete</span>\n';
                }
                action_html = action_html + '</div>';

		var atd = document.createElement('td');
		$(atd).html(action_html);
		tr.appendChild(atd);
		
		av.roles_table.appendChild(tr);
	},

        this.loadRoles = function(list, roles) {
		
                for (var key in roles) {
			var action = "add";
                        for (var lkey in list) {
                            if (roles[key].id == list[lkey].id) {
                                action = "delete";
                                break;
                            }
                        }
                        
                        var item = new Object();
			item["id"] = roles[key].id;
			item["roleValue"] = roles[key].roleValue;
			
			av.addRole(item, action);
		}
                
		$("#roles_list").append(av.roles_table);
	},
	
	
	this.editRow = function(row) {
            $("#td_email_"+row["id"]).html(row["email"]);
            $("#td_fname_"+row["id"]).html(row["fname"]);
            $("#td_lname_"+row["id"]).html(row["lname"]);
            $("#td_zip_"+row["id"]).html(row["zip"]);
            $("#td_gender_"+row["id"]).html(row["gender"]);
	},
	
	this.delRow = function(id) {
            var tr = $("#tr_"+id);
            $("#account_list").deleteRow(tr.rowIndex);
	}
	
}

